package servicesImp.notice;

import base.IBaseMapperWithoutBLOBs;
import base.IBaseServicesWithoutBLOBsImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import services.notice.NoticeAccountServices;
import services.notice.NoticeInfoServices;
import services.notice.NoticeRoleServices;
import util.key.IDFactory;
import wt.dao.notice.NoticeInfoMapper;
import wt.entity.notice.NoticeAccount;
import wt.entity.notice.NoticeInfo;
import wt.entity.notice.NoticeInfoExample;
import wt.entity.notice.NoticeRole;
import wt.staticData.TableName;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/10/14.
 */
@Service
public class NoticeInfoServicesImp extends IBaseServicesWithoutBLOBsImpl<NoticeInfo,NoticeInfoExample> implements NoticeInfoServices {
    @Autowired
    NoticeInfoMapper noticeInfoMapper;
    @Autowired
    NoticeAccountServices noticeAccountServices;
    @Autowired
    NoticeRoleServices noticeRoleServices;

    @Override
    public IBaseMapperWithoutBLOBs<NoticeInfo, NoticeInfoExample> getMapper() {
        return this.noticeInfoMapper;
    }

    @Override
    public String getTableName() {
        return TableName.NMS_NOTICE_INFO;
    }

    @Transactional
    public void insertSelectiveAnnouncement(NoticeInfo noticeInfo, List<String> roleIdList) throws Exception {

        getCurrentProxy().insertSelective(noticeInfo);


        NoticeRole noticeRole=new NoticeRole();
        for (String s : roleIdList) {
            noticeRole.setId(IDFactory.getSnowflakeId());
            noticeRole.setNoticeId(noticeInfo.getId());
            noticeRole.setRoleId(s);
            noticeRoleServices.insertSelective(noticeRole);
        }


    }
    @Transactional
    public void insertSelectiveNotice(NoticeInfo noticeInfo, List<String> accountIdList) throws Exception {



        getCurrentProxy().insertSelective(noticeInfo);

        NoticeAccount noticeAccount=new NoticeAccount();
        for (String s : accountIdList) {
            noticeAccount.setId(IDFactory.getSnowflakeId());
            noticeAccount.setNoticeId(noticeInfo.getId());
            noticeAccount.setAccountId(s);
            noticeAccountServices.insertSelective(noticeAccount);
        }


    }


    public List<NoticeInfo> select(String noticeType,String accountId, String roleId, Date startTime, Date endTime) throws Exception {

        return noticeInfoMapper.select(noticeType,accountId,roleId,startTime,endTime);
    }
}
